package com.ruoyi.common.core.utils;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.ruoyi.common.core.domain.YSResult;

public class YSUtils {
    /**
     * 获取萤石的token
     * @param appkey
     * @param masterSecret
     * @param url
     * @return
     */
    public static YSResult getToken(String appkey, String appSecret, String baseUrl){
        String url = baseUrl +"?appKey="+ appkey +"&appSecret=" + appSecret;
        HttpRequest httpRequest= HttpUtil.createPost(url).header("content-type","application/x-www-form-urlencoded");
        String resultStr = httpRequest.execute().body();
        YSResult result = JSON.parseObject(resultStr, YSResult.class);
        System.out.println(result.getAccessToken());
        return result;
    }

}
